<template>
	<view class="main">
		<viewtopnavbar></viewtopnavbar>
		<swiper
			class="swiper"
			:indicator-dots="true"
			:autoplay="true"
			:interval="3000"
			:duration="1000"
			indicator-color="rgba(38, 202, 211, 0.21)"
			indicator-active-color="rgba(38, 202, 211,.9)"
		>
			<swiper-item v-for="banner in bannerList" :key="banner.Id">
				<view class="swiper-item"><navigator :url="banner.ProUrl"><image class="img" :src="banner.ImgUrl" mode=""></image></navigator></view>
			</swiper-item>
		</swiper>

		<view class=""><viewcategory></viewcategory></view>

		<view class="body">
			<view class="box xinpin" @click="toLogin()">
				<view class="xp-1"><image src="https://res.bestcake.com/m-images-2/guanggao1.png"></image></view>
				<view class="xp-2">
					<image src="https://res.bestcake.com/m-images-2/guangao22.png"></image>
					<image src="https://res.bestcake.com/m-images-2/guanggao3.png"></image>
				</view>
			</view>
			<view class="box cainixihuan">
				<!-- 商品列表 -->
				<view class="title">— 猜你喜欢 —</view>
				<view class="product-list">
					<view class="product" v-for="product in productList" :key="product.Id">
						<image :src="product.img"></image>
						<view class="name">{{ product.name }}</view>
						<view class="info">
							<view class="price">{{ product.price }}</view>
							<view class="slogan">{{ product.slogan }}</view>
						</view>
					</view>
				</view>
				<view class="loading-text">---到底了---</view>
			</view>
		</view>
	</view>
</template>

<script>
import viewcategory from '@/components/category/category.vue';
import viewtopnavbar from '@/components/navBar/index.vue';
export default {
	components: {
		viewcategory,
		viewtopnavbar
	},
	data() {
		return {
			linkurl: '',
			title: 'Happy先生·' + '首页',
			productList: [],
			bannerList:[]
		};
	},
	onShow() {
		this.$setTitle('Happy先生·首页');
	},
	onLoad: function() {
		this.sendRequest2();
		this.getBannerList();
	},
	//微信小程序分享
	onShareAppMessage: function(res) {
		if (res.from === 'button') {
		}
		return {
			title: '冰淇淋首发，好吃',
			path: 'pages/tabBar/index',
			imageUrl: '/static/share/1.png',
			success: function(res) {
				console.log('成功', res);
			}
		};
	},
	onPullDownRefresh() {
		let that = this;
		this.sendRequest2();
	},
	methods: {
		setTitle() {},
		sendRequest2() {
			let that = this;
			uni.showNavigationBarLoading();
			this.$request
				.get('/client.ashx', {
					data: {
						c: 'WapActionCenter',
						m: 'ProCategory',
						City: '苏州'
					}
				})
				.then(res => {
					console.log(res.data);
					let result = res.data.Tag.RihghtList[0].list;

					result.map(ix => {
						that.productList.push({
							name: ix.ProductName,
							price: ix.Price,
							slogan: ix.Size,
							img: this.$resBaseurl + '/m-images/ww/jd/' + ix.ProductName + '.png'
						});
					});

					uni.hideNavigationBarLoading();
					uni.stopPullDownRefresh();
				})
				.catch(error => {
					uni.hideNavigationBarLoading();
					uni.stopPullDownRefresh();
					console.error('error:', error);
				});
		},
		toLogin() {
			let wantJumpurl = '../../pages/goodsdetail/goodsdetail';
			this.$checkLoginState(wantJumpurl);
		},
		getBannerList(){
			this.$request
				.get('/client.ashx', {
					data: {
						c: 'SwiperController',
						m: 'get',
						channel_from: 'H5',
						tabtype:'1'
					}
				})
				.then(res => {
					console.log(res.data);
					this.bannerList=res.data.Tag;
				})
				.catch(error => {
					console.error('error:', error);
				});
		}
	},
	mounted: function() {
		// #ifdef H5
		this.setTitle();
		// #endif
	}
};
</script>

<style lang="scss">
.main {
	background: #dedede;
	.swiper {
		height: 380upx;
		border-radius: 5upx;
		background: #fff;
	}

	.img {
		width: 100%;
	}
	.box {
		display: flex;
		justify-content: center;
		flex-wrap: wrap;
		width: 94%;
		padding: 40upx 3% 36upx;
		margin-top: 20upx;
		background: #fff;
		border-radius: 10px;
		box-shadow: 2upx 4upx 6upx 0px #9e9c9c;
	}
	.xinpin {
		.xp-1 {
			width: 49%;
			margin-right: 2%;

			image {
				width: 100%;
				height: 332.6upx;
			}
		}

		.xp-2 {
			width: 49%;
			image {
				width: 100%;
				height: 160upx;
			}
		}
	}
	.cainixihuan {
		background-color: #fff;
		border-radius: 10px 10px 0 0;
		.title {
			width: 100%;
			display: flex;
			justify-content: center;
			align-items: center;
			height: 60upx;
			color: #979797;
			font-size: 24upx;
		}
		.loading-text {
			width: 100%;
			display: flex;
			justify-content: center;
			align-items: center;
			height: 60upx;
			color: #979797;
			font-size: 24upx;
		}
		.product-list {
			width: 95%;
			padding: 0 2.5% 2.5vw 2.5%;
			display: flex;
			justify-content: space-between;
			flex-wrap: wrap;
			.product {
				width: 48.75%;
				border-radius: 20upx;
				background-color: #f4f4f4;
				margin: 0 0 15upx 0;
				image {
					width: 100%;
					height: 300upx;
					border-radius: 20upx 20upx 0 0;
				}
				.name {
					width: 92%;
					padding: 10upx 4%;
					display: -webkit-box;
					-webkit-box-orient: vertical;
					-webkit-line-clamp: 2;
					text-align: justify;
					overflow: hidden;
					font-size: 30upx;
				}
				.info {
					display: flex;
					justify-content: space-between;
					align-items: flex-end;
					width: 92%;
					padding: 10upx 4% 10upx 4%;

					.price {
						color: #e65339;
						font-size: 30upx;
						font-weight: 600;
					}
					.slogan {
						color: #807c87;
						font-size: 24upx;
					}
				}
			}
		}
	}
}
</style>
